/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jmenu.gui;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

;

/**
 *
 * @author Roman
 */
@Entity
@Table(name = "food",schema = "")
@NamedQueries({@NamedQuery(name = "Food.findById", query = "SELECT f FROM Food f WHERE f.id = :id"), @NamedQuery(name = "Food.findBySubsectionId", query = "SELECT f FROM Food f WHERE f.subsectionId = :subsectionId"), @NamedQuery(name = "Food.findByName", query = "SELECT f FROM Food f WHERE f.name = :name"), @NamedQuery(name = "Food.findByEnergy", query = "SELECT f FROM Food f WHERE f.energy = :energy"), @NamedQuery(name = "Food.findByCarbohydrate", query = "SELECT f FROM Food f WHERE f.carbohydrate = :carbohydrate"), @NamedQuery(name = "Food.findByProtein", query = "SELECT f FROM Food f WHERE f.protein = :protein"), @NamedQuery(name = "Food.findByFat", query = "SELECT f FROM Food f WHERE f.fat = :fat"), @NamedQuery(name = "Food.findByCholesterol", query = "SELECT f FROM Food f WHERE f.cholesterol = :cholesterol"), @NamedQuery(name = "Food.findByPictureId", query = "SELECT f FROM Food f WHERE f.pictureId = :pictureId"), @NamedQuery(name = "Food.findByState", query = "SELECT f FROM Food f WHERE f.state = :state"), @NamedQuery(name = "Food.findByAmount", query = "SELECT f FROM Food f WHERE f.amount = :amount")})
public class Food implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "subsection_id", nullable = false)
    private int subsectionId;
    @Column(name = "name", nullable = false)
    private String name;
    @Column(name = "energy", nullable = false)
    private int energy;
    @Column(name = "carbohydrate", nullable = false)
    private int carbohydrate;
    @Column(name = "protein", nullable = false)
    private int protein;
    @Column(name = "fat", nullable = false)
    private int fat;
    @Column(name = "cholesterol", nullable = false)
    private int cholesterol;
    @Column(name = "picture_id")
    private Integer pictureId;
    @Column(name = "state", nullable = false)
    private String state;
    @Column(name = "amount", nullable = false)
    private int amount;
    @Lob
    @Column(name = "Description")
    private String description;

    public Food() {
    }

    public Food(Integer id) {
        this.id = id;
    }

    public Food(Integer id, int subsectionId, String name, int energy, int carbohydrate, int protein, int fat, int cholesterol, String state, int amount) {
        this.id = id;
        this.subsectionId = subsectionId;
        this.name = name;
        this.energy = energy;
        this.carbohydrate = carbohydrate;
        this.protein = protein;
        this.fat = fat;
        this.cholesterol = cholesterol;
        this.state = state;
        this.amount = amount;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public int getSubsectionId() {
        return subsectionId;
    }

    public void setSubsectionId(int subsectionId) {
        int oldSubsectionId = this.subsectionId;
        this.subsectionId = subsectionId;
        changeSupport.firePropertyChange("subsectionId", oldSubsectionId, subsectionId);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        String oldName = this.name;
        this.name = name;
        changeSupport.firePropertyChange("name", oldName, name);
    }

    public int getEnergy() {
        return energy;
    }

    public void setEnergy(int energy) {
        int oldEnergy = this.energy;
        this.energy = energy;
        changeSupport.firePropertyChange("energy", oldEnergy, energy);
    }

    public int getCarbohydrate() {
        return carbohydrate;
    }

    public void setCarbohydrate(int carbohydrate) {
        int oldCarbohydrate = this.carbohydrate;
        this.carbohydrate = carbohydrate;
        changeSupport.firePropertyChange("carbohydrate", oldCarbohydrate, carbohydrate);
    }

    public int getProtein() {
        return protein;
    }

    public void setProtein(int protein) {
        int oldProtein = this.protein;
        this.protein = protein;
        changeSupport.firePropertyChange("protein", oldProtein, protein);
    }

    public int getFat() {
        return fat;
    }

    public void setFat(int fat) {
        int oldFat = this.fat;
        this.fat = fat;
        changeSupport.firePropertyChange("fat", oldFat, fat);
    }

    public int getCholesterol() {
        return cholesterol;
    }

    public void setCholesterol(int cholesterol) {
        int oldCholesterol = this.cholesterol;
        this.cholesterol = cholesterol;
        changeSupport.firePropertyChange("cholesterol", oldCholesterol, cholesterol);
    }

    public Integer getPictureId() {
        return pictureId;
    }

    public void setPictureId(Integer pictureId) {
        Integer oldPictureId = this.pictureId;
        this.pictureId = pictureId;
        changeSupport.firePropertyChange("pictureId", oldPictureId, pictureId);
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        String oldState = this.state;
        this.state = state;
        changeSupport.firePropertyChange("state", oldState, state);
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        int oldAmount = this.amount;
        this.amount = amount;
        changeSupport.firePropertyChange("amount", oldAmount, amount);
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        String oldDescription = this.description;
        this.description = description;
        changeSupport.firePropertyChange("description", oldDescription, description);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Food)) {
            return false;
        }
        Food other = (Food) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jmenu.gui.Food[id=" + id + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
